<template>
  <div class="inventoryPosting">
    <div class="header">
      <div class="header-name">
        <el-form :model="proVal" label-width="100px" size="mini">
          <el-form-item :label="$t('market.stareData')">
            <el-date-picker
              v-model="proVal.sd"
              type="date"
              value-format="yyyy-MM-dd"
              style="width: 175px"
            />
          </el-form-item>
          <el-form-item :label="$t('market.endData')">
            <el-date-picker
              v-model="proVal.ed"
              type="date"
              value-format="yyyy-MM-dd"
              style="width: 175px"
            />
          </el-form-item>
          <el-form-item :label="$t('market.outfbillno')">
            <el-input v-model.trim="proVal.fbillno" />
          </el-form-item>
          <el-form-item :label="$t('market.paezText1')">
            <el-input v-model.trim="proVal.sal_khddh" />
          </el-form-item>
          <el-form-item :label="$t('market.fmaterial')">
            <el-input v-model.trim="proVal.fnumber" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="mini" @click="handleQuerySonClass">{{ $t('btn.search') }}</el-button>
            <el-button type="primary" size="mini" @click="handleExport">{{ $t('btn.toExcel') }}</el-button>
          </el-form-item>
        </el-form>
        <!--        <filtration :ftype="ftype" :msg="tacitly" :select-data="selectData" :table-header="tableHeader1" @seachData="handleQuerySonClass" />-->
      </div>
    </div>
    <div class="table-content">
      <jc-table
        :table-data="tableData"
        :table-header="tableHeader"
        :table-height="tableHeight"
        serial
        sortable
        :get-summaries="getSummaries"
        show-summary
      >
        <template v-slot:tagSlot="col">
          <el-link type="primary" @click="handleInto(col.scope.row.物料编码)">
            {{ col.scope.row.物料编码 }}
          </el-link>
        </template>
      </jc-table>
    </div>
    <!--    分页器-->
    <div class="footer">
      <jc-pagination
        :total="total"
        :page.sync="currentPage"
        :limit.sync="size"
        @pagination="handleGetUntreated"
      />
    </div>
  </div>
</template>

<script>
import {
  querySaleReceivableList
} from '@/api/financial/salesMargin'
import { export_json_to_excel, formatJson } from '@/utils/Export2Excel'
import searData from '@/components/Search/mixin'

export default {
  mixins: [searData],
  data() {
    return {
      proVal: {
        sd: '',
        ed: '',
        fbillno: '',
        sal_khddh: '',
        fnumber: ''
      },
      total: 0, // 总条目
      currentPage: 1, // 当前页
      size: 200, // 每页显示多少条数据
      tableHeight: '73vh',
      // 表头
      tableData: [], // 销售数据
      tableHeader: [
        { label: this.$t('menu.marketOutBank'), prop: '销售出库单', width: '120' },
        { label: this.$t('market.cust'), prop: '客户', width: '150' },
        { label: this.$t('market.paezText1'), prop: '客户订单号', width: '110' },
        { label: this.$t('market.fmodel2'), prop: '助记码' },
        { label: this.$t('market.fmaterial'), prop: '物料编码', type: 'tag', width: '120' },
        { label: this.$t('shop.fname2'), prop: '物料名称', width: '100' },
        { label: this.$t('shop.fspecificaTion'), prop: '物料规格', width: '120' },
        { label: this.$t('shop.fdescripTion'), prop: '物料描述', width: '200' },
        { label: this.$t('market.salesAccount'), prop: '销售应收' },
        { label: this.$t('market.settleCurr'), prop: '结算币别' },
        { label: this.$t('market.exchangeRate'), prop: '汇率' },
        { label: this.$t('market.fqty'), prop: '数量', width: '70' },
        { label: this.$t('market.recCondition'), prop: '收款条件' },
        { label: this.$t('market.receiptNum'), prop: '收款天数' },
        { label: this.$t('market.deliveryTime'), prop: '出库时间' },
        { label: this.$t('market.actualReceivable'), prop: '实际应收' },
        { label: this.$t('market.collectionTime'), prop: '收款时间' },
        { label: this.$t('market.differencesDays'), prop: '差异天数' },
        { label: this.$t('market.accountReceivable'), prop: '到期应收' },
        { label: this.$t('market.overdueReceivable'), prop: '逾期应收' },
        { label: this.$t('market.localCurr'), prop: '本位币' }
      ],
      tableHeader1: []
    }
  },
  created() {
    // this.handleGetUntreated()
    this.tableHeader1 = this.tableHeader
    this.tableHeight = window.innerWidth > 1440 ? 'calc(100vh - 220px)' : '73vh'
  },
  methods: {
    // 导出表格
    handleExport() {
      require.ensure([], () => {
        const tHeader = this.tableHeader.map((res) => {
          return res.label
        })
        const filterVal = this.tableHeader.map((res) => {
          return res.prop
        })
        if (this.tableData.length <= 0) {
          this.$message.warning('没有导出数据')
        } else {
          querySaleReceivableList({
            ...this.proVal,
            pageSize: 100000,
            pageNum: 1
          }).then(res => {
            if (res.code === 0) {
              const list = res.data.array
              const data = formatJson(filterVal, list)
              export_json_to_excel(tHeader, data, '销售应付报表')
            } else {
              this.$confirm(res.message, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'error'
              })
            }
          })
        }
      })
    },
    // 获取成品配套入库表数据
    async handleGetUntreated(ev) {
      this.details = []
      if (ev && !ev.page) {
        this.details = ev
      }
      const DATA = {
        ...this.proVal,
        pageNum: this.currentPage,
        pageSize: this.size
      }
      const { data: RES } = await querySaleReceivableList(DATA)
      this.tableData = RES.array
      this.total = RES.total
    },
    // 搜索
    handleQuerySonClass(ev) {
      this.currentPage = 1
      if (ev && ev.fname) {
        this.searchSon = ev.detail
        this.customHandle(ev)
        this.handleGetUntreated(ev.detail)
      } else {
        this.handleGetUntreated()
      }
    },
    handleInto(ev) {
      this.$router.push({ path: `/detailMateriel/${ev}` })
    }
  }
}
</script>
<style lang="scss" scoped>
.inventoryPosting {
  //@include listBom;
  padding: 0;
  .header{
    position:relative;
    .header-name{
      width: 100%;
      span {
        width: 100px;
        font-size: 12px;
        text-align: center;
      }
    }
    .el-form {
      display: flex;
      flex-wrap: wrap;

      .el-form-item {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 275px;
        margin-bottom: 5px;
      }
    }
    .btn{
      transform: translateY(18%);
      margin-left: 15px !important;
    }
  }
}
</style>
